﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Funq.Tests
{
    [TestClass]
    public class ContainerKeyFixture
    {
        [TestMethod]
        public void KeysEqualByFactoryTypeAndServiceType()
        {
            var key1 = new ContainerKey(typeof(string), typeof(bool));
            var key2 = new ContainerKey(typeof(string), typeof(bool));

            Assert.AreEqual(key1, key2);
            Assert.AreEqual(key1.GetHashCode(), key2.GetHashCode());

            key1.Name = "A";
            key2.Name = "A";

            Assert.AreEqual(key1, key2);
            Assert.AreEqual(key1.GetHashCode(), key2.GetHashCode());
        }

        [TestMethod]
        public void KeysNotEqualForDifferentFactoryTypeOrServiceType()
        {
            var key1 = new ContainerKey(typeof(decimal), typeof(bool));
            var key2 = new ContainerKey(typeof(string), typeof(bool));
            var key3 = new ContainerKey(typeof(decimal), typeof(string));
            var key4 = new ContainerKey(typeof(decimal), typeof(string));

            Assert.AreNotEqual(key1, key2);
            Assert.AreNotEqual(key1, key3);

            Assert.AreNotEqual(key1.GetHashCode(), key2.GetHashCode());
            Assert.AreNotEqual(key1.GetHashCode(), key3.GetHashCode());

            key1.Name = "A";
            key2.Name = "A";
            key3.Name = "A";
            key4.Name = "B";

            Assert.AreNotEqual(key1, key2);
            Assert.AreNotEqual(key1, key3);
            Assert.AreNotEqual(key3, key4);
            Assert.AreNotEqual(key1.GetHashCode(), key2.GetHashCode());
            Assert.AreNotEqual(key1.GetHashCode(), key3.GetHashCode());
            Assert.AreNotEqual(key3.GetHashCode(), key4.GetHashCode());
        }
    }
}
